const webpack = require('webpack')
const path = require('path')

function resolve(dir) {
	return path.join(__dirname, dir)
}

module.exports = {
	outputDir: 'dist',
	publicPath: process.env.NODE_ENV === 'production' ? '/saas/' : '/',
	productionSourceMap: false,
	css: {
		loaderOptions: {
			stylus: {
				'resolve url': true,
				'import': ['./src/theme.styl']
			}
		}
	},
	devServer: {
		host: 'localhost',
		port: 8080,
		proxy: {
			'/api': {
				// dev: https://cdc.testsaas.bodajianyu.com/api
				// prod: https://cdc.saas.ins-box.com/api
				target: 'https://cdc.testsaas.bodajianyu.com/api',
				changeOrigin: true,
				pathRewrite: {
					'/api': ''
				}
			}
		}
	},
	chainWebpack(config) {
		config.resolve.alias
		.set('components', resolve('src/components'))
		.set('common', resolve('src/common'))
		.set('directives', resolve('src/directives'))
		.set('api', resolve('src/api'))
		config.plugin('context')
    .use(webpack.ContextReplacementPlugin, [/moment[/\\]locale$/, /zh-cn/])
	},
	configureWebpack(config) {
		if (process.env.NODE_ENV === 'production') {
			config.mode = 'production'
			config['performance'] = {
				'maxEntrypointSize': 10000000,
				'maxAssetSize': 30000000
			}
		}
	}
}
